package com.example.bai7;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class MyImageAdapter extends BaseAdapter{
	private Context context;
	private Integer imgid[];
	
	public MyImageAdapter(Context c)
	{
		this.context=c;
	}
	public MyImageAdapter(Context c,Integer[] imgid)
	{
		this.context=c;
		this.imgid=imgid;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return imgid.length;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ImageView imgview;
		if(convertView==null)
		{
			imgview= new ImageView(this.context);
			imgview.setLayoutParams(new GridView.LayoutParams(85,85));
			imgview.setScaleType(ImageView.ScaleType.CENTER_CROP);
			imgview.setPadding(8, 8, 8, 8);
		}
		else
		{
			imgview=(ImageView) convertView;
			
		}
		 ((BitmapDrawable)imgview.getDrawable()).getBitmap().recycle();
		imgview.setImageResource(imgid[position]);
		
		return imgview;
	}

}
